package tank.fire;

import tank.Dir;
import tank.Tank;
import tank.bullet.Bullet;
import tank.bullet.BulletGroup;

public class FourDirFireStrategy implements FireStrategy{

    /**
     * 单例模式
     */
    private FourDirFireStrategy(){

    }

    private static class FourDirFireStrategyHolder{
        private final static FourDirFireStrategy INSTANCE = new FourDirFireStrategy();
    }

    public static FourDirFireStrategy getInstance(){
        return FourDirFireStrategy.FourDirFireStrategyHolder.INSTANCE;
    }

    //四方开火, 仅我方坦克可以进行
    @Override
    public void fire(Tank tank){
        Dir[] dirs = Dir.values();
        for(Dir dir : dirs){
            new Bullet(BulletGroup.GOOD, tank.getX() + Tank.WIDTH / 2 - Bullet.WIDTH / 2, tank.getY() + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2, dir);
        }
    }

}
